﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Linq;

namespace SimWithP3d.ViewModel
{
    /// <summary>
    /// Provides bindable properties and commands for the NotifyIcon. In this sample, the
    /// view model is assigned to the NotifyIcon in XAML. Alternatively, the startup routing
    /// in App.xaml.cs could have created this view model, and assigned it to the NotifyIcon.
    /// </summary>
    public class NotifyIconViewModel
    {
        /// <summary>
        /// Shows a window, if none is already open.
        /// </summary>
        public ICommand ShowWindowCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CanExecuteFunc = () => {
                        for (int i = 0; i < Application.Current.Windows.Count; i++)
                        {
                            if (Application.Current.Windows[i].Name== "calibration")
                            {
                                return false;
                            }
                        }
                        return true;
                    },
                    CommandAction = () =>
                    {
                        Application.Current.MainWindow = new MainWindow();
                        Application.Current.MainWindow.Show();
                    }
                };
            }
        }
        /// <summary>
        /// show realData
        /// </summary>
        public ICommand ShowRealDataWindowCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CanExecuteFunc = () => {
                        for (int i = 0; i < Application.Current.Windows.Count; i++)
                        {
                            if (Application.Current.Windows[i].Name == "realData")
                            {
                                return false;
                            }
                        }
                        return true;
                    },
                    CommandAction = () =>
                    {
                        Application.Current.MainWindow = new RealDataWindow();
                        Application.Current.MainWindow.Show();
                    }
                };
            }
        }
        /// <summary>
        /// show motion platform
        /// </summary>
        public ICommand ShowMotionPlatformWindowCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CanExecuteFunc = () => {
                        for (int i = 0; i < Application.Current.Windows.Count; i++)
                        {
                            if (Application.Current.Windows[i].Name == "motionPlatform")
                            {
                                return false;
                            }
                        }
                        return true;
                    },
                    CommandAction = () =>
                    {
                        Application.Current.MainWindow = new MotionPlatformWindow();
                        Application.Current.MainWindow.Show();
                    }
                };
            }
        }
        /// <summary>
        /// Hides the main window. This command is only enabled if a window is open.
        /// </summary>
        public ICommand HideWindowCommand
        {
            get
            {
                return new DelegateCommand
                {
                    CommandAction = () => {
                        foreach (var item in Application.Current.Windows)
                        {
                            (item as Window).Close();
                        }
                    },
                    CanExecuteFunc = () => Application.Current.Windows.Count>0
                };
            }
        }


        /// <summary>
        /// Shuts down the application.
        /// </summary>
        public ICommand ExitApplicationCommand
        {
            get
            {
                return new DelegateCommand { CommandAction = () => Application.Current.Shutdown() };
            }
        }
    }
}
